package com.feishi.project.test;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: caixq
 * Date: 2018-11-26
 * Time: 上午10:10
 */
import java.awt.*;
import javax.swing.*;
@SuppressWarnings("serial")
public class ChessBoard extends JPanel{
    /*
     * 制作棋盘的宽高;
     */
    public static final int BOARD_WIDTH=515;
    /*
     * 计算棋盘表格坐标(单元格宽高相等)
     */
    public static int [] location=new int[22];
    static{
        for(int i=0,WIDTH=30;i<location.length;i++,WIDTH+=22){
            location[i]=WIDTH;
        }
    }
    public ChessBoard(int x,int y){
        super(null);
        this.setBounds(x, y, BOARD_WIDTH, BOARD_WIDTH);
        this.setBackground(new Color(255, 164, 85));
    }
    /**
     * 重写方法,绘制棋盘表格图;
     */
    public void paintComponent(Graphics g){
        super.paintComponent(g);
        char ch='A';
        g.setFont(new Font("宋体",Font.BOLD,12));
//画横线
        for(int i=0,width=30+22*21;i<location.length;i++,ch++){
            g.setColor(Color.black);
            g.drawLine(30,location[i],width,location[i]);
            g.setColor(Color.blue);
            g.drawString(""+ch,5,location[i]+3);
        }
//画竖线
        for(int i=0,width=30+22*21;i<location.length;i++){
            g.setColor(Color.black);
            g.drawLine(location[i],30,location[i],width);
            g.setColor(Color.blue);
            g.drawString(""+(i+1),location[i]-3,13);
        }
    }
}